<?php

/**
 * This is the model class for table "tbl_pessoa".
 *
 * The followings are the available columns in table 'tbl_pessoa':
 * @property string $ide_pessoa
 * @property string $nome
 * @property string $endereco
 * @property string $telefone
 * @property string $email
 * @property string $tipo
 * @property string $inscricaoEstadual
 * @property string $cpf_cnpj
 * @property string $dtc_criacao
 *
 * The followings are the available model relations:
 * @property TblEndereco $endereco0
 */
class Pessoa extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Pessoa the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_pessoa';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ide_pessoa, nome, endereco, telefone, email, tipo, inscricaoEstadual, cpf_cnpj, dtc_criacao', 'required'),
			array('ide_pessoa', 'length', 'max'=>20),
			array('nome, endereco, email, inscricaoEstadual', 'length', 'max'=>100),
			array('telefone', 'length', 'max'=>12),
			array('cpf_cnpj', 'length', 'max'=>18),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ide_pessoa, nome, endereco, telefone, email, tipo, inscricaoEstadual, cpf_cnpj, dtc_criacao', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'endereco0' => array(self::BELONGS_TO, 'TblEndereco', 'endereco'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ide_pessoa' => 'Ide Pessoa',
			'nome' => 'Nome',
			'endereco' => 'Endereco',
			'telefone' => 'Telefone',
			'email' => 'Email',
			'tipo' => 'Tipo',
			'inscricaoEstadual' => 'Inscricao Estadual',
			'cpf_cnpj' => 'Cpf Cnpj',
			'dtc_criacao' => 'Dtc Criacao',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ide_pessoa',$this->ide_pessoa,true);
		$criteria->compare('nome',$this->nome,true);
		$criteria->compare('endereco',$this->endereco,true);
		$criteria->compare('telefone',$this->telefone,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('tipo',$this->tipo,true);
		$criteria->compare('inscricaoEstadual',$this->inscricaoEstadual,true);
		$criteria->compare('cpf_cnpj',$this->cpf_cnpj,true);
		$criteria->compare('dtc_criacao',$this->dtc_criacao,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}